﻿using System;
using System.Windows;
using Microsoft.Live;
using Microsoft.Live.Controls;
using Microsoft.Phone.Controls;
using WinLiveHelper.Wp7;

namespace WinLiveHelper.UI.Wp7
{
	public partial class MainPage : PhoneApplicationPage
	{
		public MainPage()
		{
			InitializeComponent();
		}

		private void SignInSessionChangedHandler(object sender, LiveConnectSessionChangedEventArgs e)
		{
			if (e.Status == LiveConnectSessionStatus.Connected)
			{
				LiveConnectClientWrapper.Instance.Initialize(e.Session);
				LiveConnectClientWrapper.Instance.EventCreated += EventCreatedHandler;
			}
		}

		private void GetCalendarsButtonClick(object sender, RoutedEventArgs e)
		{
			LiveConnectClientWrapper.Instance.GetCalendarsAsync();
		}

		private void GetCalendarButtonClick(object sender, RoutedEventArgs e)
		{
			LiveConnectClientWrapper.Instance.GetCalendarAsync("me");
		}

		private void GetContactsButtonClick(object sender, RoutedEventArgs e)
		{
			LiveConnectClientWrapper.Instance.GetContactsAsync();
		}

		private void GetUserButtonClick(object sender, RoutedEventArgs e)
		{
			LiveConnectClientWrapper.Instance.GetUserAsync("me");
		}

		private void CreateCalendarButtonClick(object sender, RoutedEventArgs e)
		{
			var calendar = new Calendar()
							{
								Name = "SoCal Code Camp Schedule",
								Description = "My Schedule for Code Camp"
							};

			LiveConnectClientWrapper.Instance.CreateCalendarAsync(calendar);
		}

		private void CreateEventButtonClick(object sender, RoutedEventArgs e)
		{
			var newEvent = new Event()
			               	{
								Name = "Windows Live SDK for Windows Phone 7",
								StartTime = DateTime.Parse("2/28/2012 10:00AM"),
								Location = "Fullerton",
								Description = "Is this guy serious?"
			               	};

			LiveConnectClientWrapper.Instance.CreateEventAsync(newEvent, userState: "hello world");
		}

		private void EventCreatedHandler(object sender, PayloadEventArgs<Event> e)
		{
			
		}
	}
}